import java.util.ArrayList;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import aes.general.AdminControl;
public class CourseTest {

private AdminControl adminCourseStats;
	
	@Before
	public void setUp() throws Exception {
		adminCourseStats = new AdminControl();
		
	}

	@Test
	/**
	 * checks if the calculation of 4 positive numbers is genuine 
	 */
	public void testCourseStats() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		ArrayList<Double> result;
		ArrayList<Double> expected = new ArrayList<Double>();
		for(int i=0;i<4;i++)
			grades.add(i+50);
		expected.add(51.5);  //Average
		expected.add(51.5);  // median
		expected.add(4.0);   //number of grades
		result = adminCourseStats.CulcStats(grades);	
		Assert.assertEquals(result,expected);
	}
	
	@Test
	/**
	 * Checks the calculation of 4 zero numbers 
	 */
	public void testCourseStats2() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		ArrayList<Double> result;
		ArrayList<Double> expected = new ArrayList<Double>();
		for(int i=0;i<4;i++)
			grades.add(0);
		expected.add(0.0);  //Average
		expected.add(0.0);  // median
		expected.add(4.0);   //number of grades
		result = adminCourseStats.CulcStats(grades);	
		Assert.assertEquals(result,expected);
	}
	
	@Test
	/**
	 * Checks the calculations with one positive number
	 */
	public void testCourseStats3() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		ArrayList<Double> result;
		ArrayList<Double> expected = new ArrayList<Double>();
		grades.add(75);
		expected.add(75.0);  //Average
		expected.add(75.0);  // median
		expected.add(1.0);   //number of grades
		result = adminCourseStats.CulcStats(grades);	
		Assert.assertEquals(result,expected);
	}
	
	@Test
	/**
	 * Checks the calculation with one negative number
	 */
	public void testCourseStats4() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		ArrayList<Double> result;
		ArrayList<Double> expected = new ArrayList<Double>();
			grades.add(-30);
		expected.add(0.0);  //Average
		expected.add(0.0);  // median
		expected.add(1.0);   //number of grades
		result = adminCourseStats.CulcStats(grades);	
		Assert.assertEquals(result,expected);
	}

	@Test
	/**
	 * Checks the grades distribution with 4 positive grades
	 */
	public void testCourseDistribution() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		int[] expected = {0,0,2,0,1,0,0,0,0,1};
		int[] result;
		grades.add(27);
		grades.add(21);
		grades.add(45);
		grades.add(97);
		result = adminCourseStats.getDistribution(grades);
		for(int i=0 ;i<10;i++)
			Assert.assertEquals(result[i],expected[i]);	
	}

	@Test
	/**
	 * Checks the grade distribution with one grade above limit of grades
	 */
	public void testCourseDistribution2() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		int[] expected = {0,0,0,0,0,0,0,0,0,0};
		int[] result;
		grades.add(150);
		result = adminCourseStats.getDistribution(grades);
		for(int i=0 ;i<10;i++)
			Assert.assertEquals(result[i],expected[i]);	
	}
	
	@Test
	/**
	 * Checks the grade distribution with one number as limit of grades
	 */
	public void testCourseDistribution3() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		int[] expected = {0,0,0,0,0,0,0,0,0,1};
		int[] result;
		grades.add(100);
		result = adminCourseStats.getDistribution(grades);
		for(int i=0 ;i<10;i++)
			Assert.assertEquals(result[i],expected[i]);	
	}

	@Test
	/**
	 * Checks the grade distribution with one negative grade
	 */
	public void ttestTeacherDistribution4() {
		ArrayList<Integer> grades = new ArrayList<Integer>();
		int[] expected = {0,0,0,0,0,0,0,0,0,0};
		int[] result;
		grades.add(-30);
		result = adminCourseStats.getDistribution(grades);
		for(int i=0 ;i<10;i++)
			Assert.assertEquals(result[i],expected[i]);	
	}
}
